#ifndef TO_MP4_H
#define TO_MP4_H
#include "ui_mainwindow.h"
#include <QObject>
#include<QWidget>
#include<qfiledialog.h>
extern "C" {
    #include <libavcodec/avcodec.h>
    #include <libavformat/avformat.h>
    #include <libswscale/swscale.h>
    #include <libavdevice/avdevice.h>
    #include <libavformat/version.h>
    #include <libavutil/time.h>
    #include <libavutil/mathematics.h>
}
#include<qdebug.h>
#include<qfiledialog.h>
#include<qwidget.h>
#include<QPainter>
#include<QBrush>
#include<QColor>
#include<QObject>
#include<QImage>
#include<QPainter>
#include<QPen>
#include<QFont>
#include<QFile>
#include<QByteArray>
#include<QTimer>
//数据库
#include<QSqlDatabase>
#include<QMessageBox>
#include<QSqlError>
#include<QSqlQuery>
#include<QVariantList>


//背景图
//QImage img(720,404,QImage::Format_RGB888);//不好

class to_mp4 : public QObject
{
    Q_OBJECT

public:
    explicit to_mp4(QObject *parent = nullptr);
    ~to_mp4();
    double totime(QByteArray arrtime);
    void changehang(QByteArray arrtxt);
    void changehang_chi(QByteArray arrchinese);
    void setfont();
    void setother();
    double gettimelen(QString path_txt);
    double gettimelen_bysql();
    void change_jp(QByteArray arrtxt);
    //将文本存入数据
    void sql_engchi();
    //
    double gettime(int yunxinnum);
    //
    void sqlgetstr(int yunxinnum);
    //删除表
    void shanchubiao();
    void pngTomp4_2();//线程函数


signals:
    void singal_newchi(QString chi,double time);
    void signal_jieshu();

private slots:

private:
    QString NEWtxt;
    QString NEWchi;

    //单词模式,中英字幕保留
    QString danchi_1,danchi_2;
    QString engstr,chistr;

    QImage imgchuyuan;//不可设置长宽

    int width;
    int height;
    QString outFilename;
    int time_length;
    int size_egl;
    //font back
    QString qttomp4font;
    QString filename_back;
    QString filename_logo;
    int rgb_r;
    int rgb_g;
    int rgb_b;
    int rgb_r_lo;
    int rgb_g_lo;
    int rgb_b_lo;
    //
    Ui::MainWindow *ui;
    //数据库
    //
    int yunxinnum;
    int yunxinbef;
    int maxyunxin;
    double temp_time;
    int trans_id;
    int kaiqi_text_2;
    //字幕展现方式
    bool ce_subtitle_stop;
   //
    AVFormatContext *kAVFormatContext;
    AVOutputFormat *kAVOutputFormat;
    AVCodecContext *kAVCodecContext;
    AVDictionary *kAVDictionary = NULL;
    AVDictionary *opt = NULL;
    AVCodec *video_codec;
    AVStream *kAVStream;
    AVFrame *frame;
    AVFrame *tmp_frame;
    AVPacket kAVPacket = { 0 };
    struct SwsContext *kSwsContext=nullptr;
    AVRational time{1,24};  /*1s25帧*/
    AVRational time_1{1,1};  /*1s25帧*/
    uint8_t *intBuffer = 0;                           // 图片数据缓冲区
    int ret;
    int got_packer = 0;
    int64_t next_pts = 0;
};

#endif // TO_MP4_H
